<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="../../js/tools/jquery-1.4.2.min.js"></script>
<style>
table{table-layout:fixed;font-size:12px;}
  tr{background-color:#F1F6F6;}
  td{border:0px solid #D9D9D9;color:black;padding:2px;}
  .ye {clear:both;text-align:center; width:582px; height:24px;margin-top:10px; text-align:center;}
</style>
<script type="text/javascript">
function modifyInfor(id)
{
  if(check(id))
  {
	  if($("#but"+id).text()=="修改")
	  {
	     $("#title"+id).attr("disabled",false);
	     $("#descriptions"+id).attr("disabled",false);
	     $("#but"+id).html("保存");
	   }else
	   {
	       
	       var title=$.trim($("#title"+id).val());
	       var descriptions=$.trim($("#descriptions"+id).val());
	     
	       $.getJSON("../../groupbyajax/brand!photoModify.action",{photoId:id,title:title,description:descriptions},function(data){
	          if(data.success)
	          {
	             $("#title"+id).attr("disabled",true);
	             $("#descriptions"+id).attr("disabled",true);
	             $("#but"+id).html("修改");
	          }
	       });
	   }
   }
}
function delInfor(id)
{
   
    $.getJSON("../../groupbyajax/brand!photoDel.action",{photoId:id},function(data){
          if(data.success)
          {
            $("#tr"+id).remove();
          }
           
       });
}
function setFace(picId,image)
{
    $.getJSON("../../groupbyajax/brand!pictureFace.action",{picId:picId,uploadFileName:image},function(data){
          if(data.success)
          {
           alert("设置成功！");
          }
           
       });
}
function check(id)
{
   var title=$("#title"+id).val();
   var descriptions=$("#descriptions"+id).val();
   if(title.length<1||title.length>30)
   {
      alert("名称的字数在1~30之间!");
      return false;
   }
   if(descriptions.length>100)
   {
       alert("相册描述的字数不能大于100!");
      return false;
   }
   return true;
}
</script>
</head>
<body>
<a class="ye" href="picturesList.html">返回列表</a>
<table  style="width:80%;" align="center">
<s:iterator value="showPhotoList" id="id" status="status">
     <tr id="tr<s:property value="id"/>">
    <td>
      <table width="100%">
        <tr><td width="10%">名称:</td><td><input type="text" id="title<s:property value="id"/>" name="title" maxlength="30" value="<s:property value="title"/>" disabled="disabled"/></td></tr>
        <tr><td>描述：</td><td><textarea rows="2" cols="30" id="descriptions<s:property value="id"/>" name="descriptions" maxlength="100" disabled="disabled"><s:property value="description" /></textarea></td></tr>
        <tr><td colspan="2"><button id="but<s:property value="id"/>" onclick="modifyInfor(<s:property value="id"/>)">修改</button></td></tr>
      </table>
   </td>
   <td width="20%">
      <div style="text-align:center;">
           <img src="../../uploadFile/<s:property value="photoName"/>" width="150" height="150">
      </div>
      <div style="text-align:center;">
              <a href="javascript:setFace(<s:property value="picId"/>,'<s:property value="photoName"/>')">设为首页</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:delInfor(<s:property value="id"/>);">删除</a>
       </div>
   </td>
   
 </tr>
</s:iterator>
<s:if test="showPhotoList.size()==0">
 <tr id="tr<s:property value="id"/>">
    <td colspan="2" align="center">
      <font color="red">没有上传图片！</font>
    </td>
 </tr>
</s:if>
 <tr>
     <td colspan="2" align="center">
         <div class="ye">
		      
		     <s:if test="#request.showPhotoList.size()!=0">
							      <s:set name="pageUrl" >branduser!photoList.action?picId=${picId}&currentPage=</s:set>
							      <a href="${pageUrl}1">第一页</a>&nbsp;&nbsp;<a href="${pageUrl}<s:property value="#request.pages.prePage"/>">上一页</a>&nbsp;&nbsp;
							      <s:set name="totalPage" value="#request.pages.totalPage"></s:set>
							      <s:set name="currentPage" value="#request.pages.currentPage"></s:set>
							   <s:if test="#currentPage<=0">
							      <s:set name="currentPage" value="1"></s:set>
							   </s:if>
							   <s:elseif test="#currentPage>#totalPage">
							      <s:set name="currentPage" value="#totalPage"></s:set>
							   </s:elseif>
							   
							   <s:if test="#totalPage%6>0">
							       <s:set name="pageSize" value="#totalPage/6+1"></s:set>
							   </s:if>
							   <s:else>
							       <s:set name="pageSize" value="#totalPage/6"></s:set>
							   </s:else>
							  
							   
							   <s:if test="#currentPage%6>0">
							       <s:set name="cPageSize" value="#currentPage/6+1"></s:set>
							   </s:if>
							   <s:else>
							       <s:set name="cPageSize" value="#currentPage/6"></s:set>
							   </s:else>
							   
							   <s:set name="first" value="6*(#cPageSize-1)"></s:set>
							   <s:if test="#first==0">
							      <s:set name="first" value="1"></s:set>
							   </s:if>
							   <s:set name="last" value="#cPageSize*6"></s:set>
							   <s:if test="#last>#totalPage">
							      <s:set name="last" value="#totalPage"></s:set>
							   </s:if>
				
							     <s:bean name="org.apache.struts2.util.Counter" id="counter"> 
							       <s:param name="first" value="#first"/>
							       <s:param name="last" value="#last" />
							       <s:iterator status="status"> 
							         <s:if test="#currentPage==(#status.index+#first)">
							            &nbsp;&nbsp;<s:a href="%{pageUrl}%{#status.index+#first}" cssStyle="background-color:#982987;color:#FFFFFF; padding-right:3px; padding-left:3px;" ><s:property value="#status.index+#first" /></s:a>
							         </s:if>
							         <s:else>
							            &nbsp;&nbsp;<s:a href="%{pageUrl}%{#status.index+#first}" ><s:property value="#status.index+#first" /></s:a>
							         </s:else>
							       </s:iterator> 
							     </s:bean>
							     <s:if test="#last<#totalPage">
							       ......&nbsp;
							     </s:if>
		                       <a href="${pageUrl}<s:property value="#request.pages.nextPage"/>">下一页</a>&nbsp;&nbsp;<a href="${pageUrl}<s:property value="#request.pages.totalPage"/>">最后一页</a>
		             </s:if> 
	   </div> 
     </td>
 </tr>
</table>
</body>
</html>